﻿using FastCloud.Base.Config;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastCloud.Base.Desgin
{
    public class TreeNode
    {
        [JsonProperty("id")]
        public string ID { set; get; }
        [JsonProperty("name")]
        public string Name { set; get; }
        [JsonProperty("pid")]
        public string PID { set; get; }
        [JsonProperty("checked")]
        public bool Checked { set; get; }
        [JsonProperty("istop")]
        public bool IsTop { set; get; }
        [JsonProperty("isParent")]
        public bool IsParent { set; get; }
        [JsonProperty("open")]
        public bool Open { set; get; }
        [JsonProperty("icon")]
        public string Icon { set; get; }
        [JsonProperty("iconClose")]
        public string IconClose { set; get; }
        [JsonProperty("iconOpen")]
        public string IconOpen { set; get; }
        [JsonProperty(PropertyName = "children", NullValueHandling = NullValueHandling.Ignore)]
        public List<TreeNode> Children { set; get; }
        [JsonProperty("extra")]
        public Dictionary<string, object> Extra { set; get; }

        public TreeNode()
        {
            Extra = new Dictionary<string, object>();
            IsTop = false;
            Open = false;
            IsParent = false;
            Icon = CloudUtil.GetRootPath() + "images/tree_leaf_icon.png";
            IconClose = CloudUtil.GetRootPath() + "images/tree_folder_iocn.png";
            IconOpen = CloudUtil.GetRootPath() + "images/tree_folderopen_iocn.png";
        }

        public void AddExtra(string Key, object Value)
        {
            Extra.Add(Key, Value);
        }

        public void AddChildNode(TreeNode Node)
        {
            if (Children==null)
            {
                Children = new List<TreeNode>();
            }
            Children.Add(Node);
        }
    }
}
